#include <iostream>
#include <algorithm>
using namespace std;
const int N = 310;
struct S
{
	int id;
	int chinese;
	int math; 
	int eng;
	int total;
}s[N];
bool cmp(struct S s1, struct S s2)
{
	if (s1.total != s2.total)
		return s1.total > s2.total;
	else if (s1.chinese != s2.chinese)
		return s1.chinese > s2.chinese;
	else
		return s1.id < s2.id;
}
int main()
{
	int n = 0;
	cin >> n;
	int i = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> s[i].chinese >> s[i].math >> s[i].eng;
		s[i].id = i;
		s[i].total = s[i].chinese + s[i].math + s[i].eng;
	}
	sort(s + 1, s + 1 + n, cmp);
	for (i = 1; i <= 5; i++)
	{
		cout << s[i].id << " " << s[i].total << endl;
	}
	return 0;
}